package com.thinkfit.jy.utils;

import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.thinkfit.jy.R;
import com.thinkfit.jy.view.CCTrackView;

/**
 * 返回按钮（用于在第三方应用中返回本应用）
 */
public class TestViewUtils {

    private static TestViewUtils backButtonViewUtils;
    WindowManager windowManager;

    boolean isFist = true;

//    CarTrackView trackView;
    CCTrackView trackView;
    View inflate;

    public static TestViewUtils getInstance(){
        if(backButtonViewUtils == null){
            backButtonViewUtils = new TestViewUtils();
        }
        return backButtonViewUtils;
    }


    public void initView(Context context){
        if(windowManager == null){
            windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        }
        if(inflate == null){
            inflate = LayoutInflater.from(context).inflate(R.layout.item_test, null);


        }
        trackView = inflate.findViewById(R.id.trackView);

        System.out.println("ddddddddddddddddddddddd   trackView  "+(trackView == null));


        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT
        );

        layoutParams.gravity = Gravity.LEFT| Gravity. TOP;

        if(isFist){
            isFist = false;
            windowManager.addView(inflate,layoutParams);
        }else {
            inflate.setVisibility(View.VISIBLE);
        }

    }

    public void setInfo(float d){
        if(inflate == null){
            return;
        }

    }

    public void goneButton(){
        if(windowManager != null){
            if(inflate != null){
                inflate.setVisibility(View.GONE);
            }
        }

    }


}
